package com.xycake.controller.client;

import com.xycake.entity.User;
import com.xycake.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/myroom")
public class MyRoomController {

    @Autowired
    private UserService userService;

    @RequestMapping("/user")
    public void xycakeOrders(HttpSession session, String showName, String tel, String password,String email, String sex, String address) {
        User u = (User) session.getAttribute("loginUser");
        User user = new User();
        user.setShowName(showName);
        user.setTel(tel);
        user.setUsername(u.getUsername());
        user.setPassword(password);
        user.setType(0);
        user.setDelMark(0);
        user.setEmail(email);
        user.setSex(sex);
        user.setAddress(address);
        user.setId(u.getId());
        userService.insertUserById(user);
    }

    @RequestMapping("/init")
    public Map<String,Object> init(HttpSession httpSession){
        User loginUser = (User) httpSession.getAttribute("loginUser");
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("data", userService.selectAllByUser(loginUser.getUsername()));
        return map;
    }

}
